/*
 * @Author: liu
 * @Date: 2024-04-19 23:23:26
 * @LastEditors: liu
 * @LastEditTime: 2024-04-22 00:03:59
 * @FilePath: \yyx_ser_ts\app\demo\demo.ts
 * @Description:
 * 天道酬勤
 */
import Router, { RouterContext } from 'koa-router'
import { get, post, controller, use, unifyUse } from '../router/decorator/index'
import commonMiddleware from '../middleware/common'
import { Context } from 'koa'

/** 装饰器router clsss */
export type RouterController<T extends string> = {
  [key in T]: (ctx: Context) => Promise<void>
}

console.log('222')
type MethodName = 'getName' | 'postName'

@controller('/demo')
@unifyUse<MethodName>(commonMiddleware)
class DemoRouteModule implements RouterController<MethodName> {
  //  @use(commonMiddleware)
  @get('/aa')
  async getName(ctx: Context) {
    ctx.body = 'demo1'
  }

  @post('/aa')
  async postName(ctx: Context) {
    const { name } = ctx.request.body
    ctx.body = {
      name: name
    }
  }
}
